package _01SimpleFactoryDesignPattern;


import common.Fruit;

public class FruitFactory {
    public static Fruit getFruit(String type) throws IllegalAccessException, InstantiationException, ClassNotFoundException {
        //1.利用equalsIgnoreCase 可以增强适用性
//         if(type.equalsIgnoreCase("apple")){
//            return Apple.class.newInstance();
//        }else if(type.equalsIgnoreCase("banalan")){
//            return Bananan.class.newInstance();
//        }else{
//            System.out.println("找不到对应的类");
//            return  null;
//        }
        //2.利用Class.forName("xxx.xx")方法    Class.forName(xxxx)参数不是绝对路径，请写包名+类名
        //Class.forName()的 更多常识     https://www.cnblogs.com/beast-king/p/6807257.html
        Class<?> fruit = Class.forName("common."+type);
        return (Fruit) fruit.newInstance();

    }
}
